use std::collections::HashMap;

fn main() {
    let mut users = HashMap::new();
    users.insert("张飞".to_string(), "翼德".to_string());
    users.insert("刘备".to_string(), "玄德".to_string());
    users.insert("关羽".to_string(), "云长".to_string());

    let jx = String::from("贾诩");
    let wh = String::from("文和");
    users.insert(jx, wh);

    for (nm, zi) in &users{
        println!("{}: {}", &nm, &zi);
    }

    println!("{}", users.entry(String::from("孙权")).or_insert(String::from("仲谋")));
    println!("{}", users.entry(String::from("贾诩")).or_insert(String::from("WH")));

    // println!("{:?}", users);
    // println!("{}", jx);
    // println!("{}", wh);

    let uss = vec!["php".to_string(), "java".to_string(), "python".to_string()];
    let ranks = vec![20, 30, 40];
    let x = 22;
    let kv = String::from("php");
    let mut rhash: HashMap<_,_> = uss.iter().zip(ranks.iter()).collect();
    rhash.insert(&kv, &x);
    println!("{:?}", rhash);

    let mut counter = HashMap::new();
    counter.insert(String::from("A"), 1);
    counter.insert(String::from("B"), 2);
    counter.insert(String::from("C"), 3);
    println!("{:?}", counter);

    let text = "hello world wonderful world world am world hello";
    let mut map = HashMap::new();
    for word in text.split_whitespace() {
        let count = map.entry(word).or_insert(0);
        *count += 1;
    }
    println!("{:?}", map);
}
